package me.cloudcat.develop.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.springframework.util.Base64Utils;

/**
 * 字符串工具类
 *
 * @author ZZWang
 * @Time 2017年6月28日 下午5:53:59
 *
 */
public class StringUtils {

	/**
	 * md5加密
	 * @param str
	 * @return
	 */
	public static String md5(String str) {
		String pass = null;
		if (org.apache.commons.lang3.StringUtils.isNoneBlank(str)) {
			try {
				MessageDigest md5 = MessageDigest.getInstance("md5");
				byte[] digest;
				digest = md5.digest(str.getBytes("utf-8"));
				pass = Base64Utils.encode(digest).toString();
			} catch (NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			throw new NullPointerException();
		}
		return pass;
	}

}
